using System;
using System.Collections.Generic;
using System.Text;

namespace Scenario_Editor.WR2TerrainLoader
{
    class ObjectName
    {
        char[] chars = new char[32];

        internal ObjectName(char[] name)
        {
            for (int i = 0; i < name.Length; i++)
            {
                this.chars[i] = name[i];
                //if (name[i] == '\0')
                //    break;
            }
        }
        internal ObjectName(byte[] name)
        {
            bool fillWithNull = false;

            for (int i = 0; i < name.Length; i++)
            {
                if (!fillWithNull)
                    this.chars[i] = Convert.ToChar(name[i]);
                else
                    this.chars[i] = '\0';
                
                if (name[i] == '\0')
                    fillWithNull = true;
            }
        }

        public char[] Chars { get { return chars; } set { chars = value; } }

        internal static ObjectName LoadFromStream(System.IO.BinaryReader br)
        {
            ObjectName test = new ObjectName(br.ReadChars(32));

            return test;// new ObjectName(br.ReadChars(32));
        }
        internal static ObjectName LoadFromStreamByte(System.IO.BinaryReader br)
        {
            ObjectName test = new ObjectName(br.ReadBytes(32));

            return test;// new ObjectName(br.ReadChars(32));
        }

        public override string ToString()
        {
            string test = new string(chars);
            string[] splittet = test.Split("\0".ToCharArray());
           //return  test.Replace('\0', ' ');
            return splittet[0];
        }

        internal void Save(System.IO.BinaryWriter bw)
        {
            bw.Write(this.chars);
        }
    }
}
